//
//  UserSetting.m
//  NetImager
//
//  Created by li hongliang on 10-9-6.
//  Copyright 2010 sweet-home. All rights reserved.
//

#import "UserSetting.h"

@implementation UserSetting

@synthesize userName = _userName;
@synthesize passWord = _passWord;
@synthesize uploadURL = _uploadURL;

#pragma mark init
//- (id) init
//{
//	if(self = [super init]) 
//	{
//		self.userName = [NSString string];
//		self.passWord = [NSString string];
//		self.uploadURL = [NSString string];
//
//	}
//	return self;
//}

#pragma mark sender's function 

/*
 *  Description: load the picture site setting 
 *
 *  keyStr:  UserDefaults key, eg. DOUBAN  FLICKER  TWINTTER
 */
- (BOOL) loadUserSetting: (NSString *)siteKeyStr
{
	NSDictionary *dictionary = [[NSUserDefaults standardUserDefaults] objectForKey:siteKeyStr];
	if(dictionary != nil) {
		[self.userName release];
		[self.passWord release];
		[self.uploadURL release];
		self.userName = [dictionary objectForKey:@"Username"];
		self.passWord = [dictionary objectForKey:@"Password"];
		self.uploadURL = [dictionary objectForKey:@"UploadURL"];
		return YES;
	}
	else {
		return NO;
	}
}

/*
 *  Description: write the picture site setting 
 *
 *  keyStr:  UserDefaults key, eg. DOUBAN  FLICKER  TWINTTER
 */

+ (void) writeUserSetting: (NSString *)siteKeyStr 
					username:(NSString *)name
					password:(NSString *)pass
				   uploadURL:(NSString *)url
{
	NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:name, @"Username", pass, @"Password", url, @"UploadURL", nil];
	[[NSUserDefaults standardUserDefaults] setObject:dictionary forKey:siteKeyStr];
	
}

- (void) dealloc {
	[self.userName release];
	[self.passWord release];
	[self.uploadURL release];
	[super dealloc];
}
@end
